package edu.ck.drawTest;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;

public class drawView extends View{
	private int x1, x2 , y1,y2;
	private int touchX, touchY;
	private int touchAction;
	
	public drawView(Context context){
		super(context);
		setBackgroundColor(Color.WHITE);
		setFocusable(true);
//		setFocusableInTouchMode(true);
	}
	
	
	@Override
	protected void onDraw(Canvas canvas){
		Paint paint = new Paint();
		paint.setColor(Color.BLUE);
		
		canvas.drawRect(x1, y1, x2, y2, paint);

		if(touchAction == MotionEvent.ACTION_DOWN){
			x1 = touchX;
			y1 = touchY;
		}
		if(touchAction == MotionEvent.ACTION_UP){
		}
		if(touchAction == MotionEvent.ACTION_MOVE){
			x2 = touchX;
			y2 = touchY;
		}	

	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event){
		touchX = (int)event.getX();
		touchY = (int)event.getY();
		touchAction = event.getAction();
		return true;
	}
}
